import scrapy
import json
from ..items import EastmoneyItem


class MoneySpider(scrapy.Spider):
    name = "money"
    allowed_domains = ["http://65.push2.eastmoney.com"]
    start_urls = ["http://65.push2.eastmoney.com/api/qt/clist/get?cb=jQuery112406736638761710398_1697718587304&pn=1&pz=20&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&wbp2u=|0|0|0|web&fid=f3&fs=m:0+t:6,m:0+t:80,m:1+t:2,m:1+t:23,m:0+t:81+s:2048&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152&_=1697718587305"]

    def parse(self, response):
        number=1
        response = response.text
        response=response[42:-2]
        data=json.loads(response)
        data = data['data']['diff']
        for d in data:
            item=EastmoneyItem()
            item['data']=d
            item['number']=number
            number+=1
            yield item
